package com.waimai.demo.Service.Serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.jnlp.IntegrationServiceImpl;
import com.waimai.demo.Dao.CategoryMapper;
import com.waimai.demo.Service.CategoryService;
import com.waimai.demo.Service.DishService;
import com.waimai.demo.back.runtimeException;
import com.waimai.demo.domain.Category;
import com.waimai.demo.domain.Dish;
import com.waimai.demo.domain.Setmeal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    DishServiceImpl dishService;

    public void remove(Long id) {
        LambdaQueryWrapper<Dish> lqm = new LambdaQueryWrapper<>();
        lqm.eq(Dish::getCategoryId, id);
        int count = dishService.count(lqm);
        if (count > 0) {
            throw new runtimeException("关联菜品了哦铁子，删不了");
        }
        LambdaQueryWrapper<Setmeal> lqm1 = new LambdaQueryWrapper<>();
        lqm1.eq(Setmeal::getCategoryId, id);
        int count1 = dishService.count(lqm);
        if (count1 > 0) {
            throw new runtimeException("关联套餐了哦铁子，删不了");
        }
        super.removeById(id);
    }
}
